// pages/collect/index.js
const {http}=require("../../utils/http");
const {
  collectionDelete
}
=require("../../utils/insertAndDelete");
Page({
  data:{
    collection:[]
  },
  onLoad:function(option){
    var url="http://122.112.245.197:5000/api/collection"
    http({
      url,
      success:(res)=>{
        var collection=[];
        res.data.forEach(item=>{
          if(!wx.getStorageSync('iphone')){
            return false;
          }
          else if(item.userID==wx.getStorageSync('iphone')){
            collection.push(item);
          }
        })
        this.setData({
          collection:collection
        })
      }
    })
  },
  click(e){
    console.log(e.currentTarget.id)
    wx.navigateTo({
      url: `/pages/goods_detail/index?id=` +e.currentTarget.dataset.aid,
    })
  },
  concel(e){
    var data={
      pID:e.currentTarget.dataset.aid
    }
    collectionDelete({
      data,
      success:(res)=>{
        console.log(res);
      }
    })
    this.onLoad();
  }
})